<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>  
<!doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="copyright" content=""/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
	<title>设置-账号管理</title>
	<link href="../favicon.ico" rel="shortcut icon">
	<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
	<link href="${pageContext.request.contextPath}/css/system/public.css" />
	<link href="${pageContext.request.contextPath}/css/system/set.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath}/css/system/alert.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<style type="text/css">
#department_name>li:nth-child(5){
	background:white
}
#department_name>li:nth-child(5):hover{
	background:#03a9f4;
}
.m_xpages .mian a.pageDisable {
    color: #bdbdbd;
}
.igray{
    background:#ddd;
}
.iblue{
    color:#03a9f4;
}
</style>
</head>
<body class="gray-bg">
	<div class="s_popup_delect2">
		<div class="s_consum">
			<p id="dialog_title"></p>
		</div>
    </div>
   <div class="wrapper wrapper-content animated fadeInRight"> 
    <div class="row">
        <div class="s_role com-md-12">
            <ul class="s_role_condition fix">                
                <li>关键字<input type="text" placeholder="输入姓名、电话、职位" id="keyWord"maxlength = "20"/></li>
                <li>状态
                    <div class="select">
                      <span id="status">全部</span>
                      <div class="selectBox">
                        <ul>
                          <li>全部</li>
                          <li>正常</li>
                          <li>失效</li>
                        </ul>
                      </div>
                      <i class="dropImg"><img src="${pageContext.request.contextPath}/images/system/dropDown.png"/></i>
                    </div>
                </li>
                <li>角色                    
                    <div class="select">
                      <span id="role">全部</span>
                      <div class="selectBox">
                        <ul id='role_name'>
                          <li>全部</li>
                        </ul>
                      </div>
                    <i class="dropImg"><img src="${pageContext.request.contextPath}/images/system/dropDown.png"/></i>
                    </div>
                </li>
                <li>部门                    
                    <div class="select">
                      <span id="department">全部</span>
                      <div class="selectBox">
                        <ul id="department_name">
                        	<li>全部</li>
                        </ul>
                      </div>
                    <i class="dropImg"><img src="${pageContext.request.contextPath}/images/system/dropDown.png"/></i>
                    </div>
                </li>
                <shiro:hasPermission name="sys_account_search_button"> 
                <li id='searchA'><i><img src="${pageContext.request.contextPath}/images/system/icon_search.png" /></i></li>
                </shiro:hasPermission>
                <shiro:hasPermission name="sys_account_create_button"> 
                <li><a href="javascript:;" class="J_s_box" ><img src="${pageContext.request.contextPath}/images/system/add_2.png" />添加账号</a></li>
                </shiro:hasPermission>
            </ul>
            <table id="userList">
                <thead>
                    <tr>
                      <th>编号</th>
                      <th>姓名</th>
                      <th>电话</th>
                      <th>邮箱</th>
                      <th>职位</th>
                      <th>角色</th>
                      <th>部门</th>
                      <th>状态</th>
                      <th>操作</th>
                    </tr>
                </thead>
                <tbody>
 <!--                    <tr>
                      <td>001</td>
                      <td>刘璐</td>
                      <td>18392817283</td>
                      <td>cutelili8023@163.com</td>
                      <td>总经理</td>
                      <td>超级管理员</td>
                      <td>上海分公司</td>
                      <td class="k_sx">失效</td>
                      <td>
                        <a href="javascript:;" class="k_bj">编辑</a>   
                        <a href="javascript:;" class="k_qy">启用</a>
                        <a href="javascript:;" class="k_sc">删除</a> 
                      </td>
                    </tr> -->
                </tbody>
            </table>
            <div id="warning_word" style="color:red;text-align:center;"></div>
            <div class="m_xpages">
                <div class="mian">
                    <span>显示行数</span>
                    <select><option>10</option><option>20</option><option>50</option></select>
                    <span>共0条</span>
                    <span>1/1页</span>
                    <a href="javascript:;" class="prev">上一页</a>
                    <a href="javascript:;" class="next">下一页</a>
                    <span>前往</span>
                    <input type="text" value="1" class="text">
                    <span>页</span>
                </div>
            </div>
        </div>
    </div>
</div>
   </div>
    <!-- 添加账号弹框 -->
    <div class="s_popup">
        <div class="issue s_xk_issue">
            <span><img src="${pageContext.request.contextPath}/images/system/close.png" /></span>
            <h4>添加账号</h4>
            <ul class="fix" style="height: 350px;overflow-y: auto;">
                <li>
                    <span><i style="color:red;">*</i>姓名</span>
                    <div class="s_input_box" >
                        <input type="text" id="name"maxlength = "10"/>
                    </div>
                </li>
                <li>
                    <span><i style="color:red;">*</i>电话</span>
                    <div class="s_input_box" >
                        <input type="text" id="account"maxlength = "11"/>
                    </div>
                </li>
                <li>
                    <span>邮箱</span>
                    <div class="s_input_box" >
                        <input type="text" id="email"maxlength = "30"/>
                    </div>
                </li>
                <li>
                    <span><i style="color:red;">*</i>职位</span>
                    <div class="s_input_box" >
                        <input type="text" id="job" maxlength = "20">
                    </div>
                </li>
                <li><span><i style="color:red;">*</i>部门</span>
                    <div class="select fL" style="width:200px;">
                      <span id="depart_span" style="width: 90%;text-align: left;"></span>
                      <div class="selectBox">
                        <ul id="department_select_name">
                        </ul>
                      </div>
                     <i class="s_dropImg" ><img src="${pageContext.request.contextPath}/images/system/dropDown.png"/></i>
                    </div>                    
                </li>
                <li style="margin-top:-12px;">
                    <span><i style="color:red;">*</i>角色</span>
                    <ol class="fix" id="roles">
                    </ol>
                </li>
                <!-- <div style="clear:both;"></div> -->
            </ul>
            <!-- <div style="clear:both;"></div> -->
            <div id="warning_word_tb" style="color:red;text-align:center;"></div>
             <!-- <div style="clear:both;"></div> -->
            <p><a id="submit" href="javascript:;">完成</a></p>
        </div>
    </div>

    <!-- 添加账号成功弹框 -->
    <div class="s_popup_box k_cg_bg">
        <div class="s_popup_detailed k_cg_content">
            <span><img src="${pageContext.request.contextPath}/images/system/close.png" /></span>
            <h4><img src="${pageContext.request.contextPath}/images/system/icon_hint.png" /> 账号添加成功</h4>
            <h5>登录码已经发送至<i id="add_b_pho"></i>中</h5>
            <h5>请在<i>7天内</i>登录并设置个人信息，否则账号<em>失效！</em></h5>
            <p><a href="javascript:;" id="k_cg_wc">完成</a></p>
        </div>
    </div>

    <!-- 账号启用成功弹框 -->
    <div class="s_popup_box k_qy_bg">
        <div class="s_popup_detailed k_qy_content">
            <span><img src="${pageContext.request.contextPath}/images/system/close.png" /></span>
            <h4><img src="${pageContext.request.contextPath}/images/system/icon_hint.png" /> 账号启用成功</h4>
            <h5>账号启用成功</h5>
            <h5>系统将以短信的形式通知<i id="qy_b_pho"></i></h5>
            <p><a href="javascript:;" id="k_qy_wc">完成</a></p>
        </div>
    </div>

    <!-- 账号停用成功弹框 -->
    <div class="s_popup_box k_ty_bg">
        <div class="s_popup_detailed k_ty_content">
            <span><img src="${pageContext.request.contextPath}/images/system/close.png" /></span>
            <h4><img src="${pageContext.request.contextPath}/images/system/icon_hint.png" /> 账号停用成功</h4>
            <h5>账号停用成功</h5>
            <h5>系统将以短信的形式通知<i id="ty_b_pho"></i></h5>
            <p><a href="javascript:;" id="k_ty_wc">完成</a></p>
        </div>
    </div>
        <!-- 删除弹框 -->
    <div class="s_popup_box s_popup_delect">
        <div class="s_popup_detailed issue_delect">
            <span><img src="${pageContext.request.contextPath}/images/system/close.png" /></span>
            <h4><img src="${pageContext.request.contextPath}/images/system/warning.png" />删除账号</h4>
            <h5>确定要删除此账号吗？</h5>
            <p><a href="javascript:;" class="s_cancel_del">取消</a> <a href="javascript:;" class="s_confirm_del">确定</a></p>
        </div>
    </div>
            <!-- 停用弹框 -->
    <div class="s_popup_box s_popup_ty">
        <div class="s_popup_detailed issue_ty">
            <span><img src="${pageContext.request.contextPath}/images/system/close.png" /></span>
            <h4><img src="${pageContext.request.contextPath}/images/system/warning.png" />停用账号</h4>
            <h5>确定要停用此账号吗？</h5>
            <p><a href="javascript:;" class="s_cancel_ty">取消</a> <a href="javascript:;" class="s_confirm_ty">确定</a></p>
        </div>
    </div>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/system/exit.js"></script>
<%--  <script type="text/javascript" src="${pageContext.request.contextPath}/js/accountlist.js"></script> --%>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<!-- 退出 -->
<script type="text/javascript">
var path = "<%=path%>";
/* 添加、编辑按钮*/
//添加、编辑按钮
$(document).on('click','.J_s_box,.k_bj',function(){
	
	//编辑
	if($(this).prop("class")=="k_bj"){
		var id = $(this).attr('userId');
		$.post(path+'/api/account/sysuserDetail', {
			"id": id,			
		}, function(data) {
			$(".s_popup>.issue>h4").text("编辑账号");
			$("#name").addClass("igray");
			$("#account").addClass("igray");
			$("#name").val(data.userInfo.sname).attr("readonly",true);        			
			$("#account").val(data.userInfo.saccount).attr("readonly",true);
			$("#email").val(data.userInfo.semail);
			$("#job").val(data.userInfo.sjob);
			//部门
			$(".fL>span").text(data.userInfo.departmentName);
			$('#depart_span').attr("departid",data.userInfo.sdepartment_id); 
			//角色，超级管理员在角色列表显示，在选中的角色下面打勾       	     			
			$("#roles").html("");
			$.each(data.roleInfo,function(i,d){
				var str = "";
  			str += '<li class="s_fx_li1"><img src="${pageContext.request.contextPath}/images/system/s_check.png" class="s_fk_pic1" _id="'+d.id+'" />'+d.name+'</li>';
  			$("#roles").append(str);
			}); 
			
			if(data.userInfo.roleId != undefined){
  			$.each(data.userInfo.roleId.split(","),function(i,d){
  				$("#roles>li>img[_id='"+d+"']").prop("src","${pageContext.request.contextPath}/images/system/s_check_no.png");
  			});
			}
			//提示框置空
			wword.text("");
			//选出用户匹配的角色打钩
			//在完成按钮上附上id值
			$('.s_xk_issue p').attr("userid",data.userInfo.aid); 
			//在框中显示
			$('.s_popup').show();
          $('.issue').show();
	   });
	}else{
		//添加
		$.post(path+'/api/account/getRoles', {							
		}, function(data) {	        			
		$(".s_popup>.issue>h4").text("添加账号");
		$("#name").removeClass("igray");
		$("#account").removeClass("igray");
		$("#name").val('').attr("readonly",false);
		$("#account").val('').attr("readonly",false);
		$("#email").val('');
		$("#job").val('');
		//部门
		$(".fL>span").text("");
		$('#depart_span').attr("departid",null);
		//角色，   	     			
		$("#roles").html("");
		$.each($.parseJSON(data.obj),function(i,d){
			var str = "";
			str = '<li class="s_fx_li1"><img src="${pageContext.request.contextPath}/images/system/s_check.png" class="s_fk_pic1" _id="'+d.id+'" />'+d.name+'</li>';
			$("#roles").append(str);
		}); 
		//提示框置空
		wword.text("");
		//显示弹框
      $('.s_popup').show();
      $('.issue').show();
	});
}
});        	
/* <!----------------------  添加、编辑按钮结束------------------ --> */
$('.s_popup .issue > span').click(function(){
  $('.s_popup').hide();
  $('.issue').hide();
});
$('.s_popup_detailed span').click(function(){
  $('.k_cg_bg').hide();
  $('.k_cg_content').hide();
  $('.k_qy_bg').hide();
  $('.k_qy_content').hide();
  $('.k_ty_bg').hide();
  $('.k_ty_content').hide();
}); 

$(document).on("click",".s_fx_li1>img",function(){
	var src = $(this).attr('src');
  if(src.indexOf('s_check.png')>0){
    $(this).attr('src', '${pageContext.request.contextPath}/images/system/s_check_no.png');
  }else{
    $(this).attr('src', '${pageContext.request.contextPath}/images/system/s_check.png');
  }
});
$(function(){
	$(document).on('click','.selectBox ul li',function(){
	    var text = $(this).text();
	    $(this).parents('.select').find('span').text(text);
	    if($(this).attr('_depart_Id')!=null){
	        var id=$(this).attr('_depart_Id');
	        $('#depart_span').attr("departid",id); 
	    }                      
})

$('.select').on('click',function(){
	  $(this).toggleClass('selectState');
	  if(!$(this).hasClass('selectState')){
		  $('.select').removeClass('selectState');
		  $(this).next().find('img').attr('src','${pageContext.request.contextPath}/images/system/dropDown.png');
	  }else{
		  $(this).next().find('img').attr('src','${pageContext.request.contextPath}/images/system/dropUp.png');
	  }
})
})
$(function(){
//添加栏目邮件格式判断
$('#email').blur(function(){
	//用户输入的密码
	var email=$('#email').val();
	if(email==null || email==""){
		wword.text("");
		return;
	    }
	//正则表达式
	var reg=/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
	//判断
	if(!reg.test(email)){
		 wword.text("不符合邮件地址规范");
	    //document.getElementById("email").value="";			    
	}else{
		wword.text("");
		//alert("有效的邮件地址");
	}
});
})        
/*邮箱格式判断结束*/
/*添加栏目验证手机号码*/	
var wword = $("#warning_word_tb");
//添加栏目验证手机号码
$(function(){
	$('#account').blur(function(){
		var tel = $('#account').val();
		if(tel==null || tel==""){					
			wword.text("");
			return;
		    }
		var reg =/^1(3|4|5|7|8)\d{9}$/;//正则表达式 				
		//var tel=document.getElementById("zc_mobile"); 
		//匹配
		var result = reg.test(tel);				
		if(!result){
			//手机号格式不正确，执行下面
			wword.text("不是正确的11位手机号");
			//document.getElementById("account").value=""; 
			//$('#account').focus();
		}else{  
			wword.text("");
			//手机号格式正确
			//alert("true");
		}
	});
})		
/*添加栏目验证手机号码结束*/
/*“完成”点击事件*/
//添加栏目，点击“完成”，触发点击事件
$(function(){
	$('#submit').click(function(){
		if(wword.text()=="不符合邮件地址规范"||wword.text()=="不是正确的11位手机号"){
			return;
		}
		//名字
		var name = $('#name').val();   //alert("name"+name);
	    //电话  	   	    
	    var account = $('#account').val(); //alert("account"+account);    	    	        	    	 
	       //邮箱	    	
	    var email = $('#email').val(); //alert("email "+email ); 
	       //职位
	    var job=$('#job').val(); //alert("job"+job); 
	       	//状态
	    var department = $("#depart_span").attr('departid'); //alert("departmentid"+department);
	       	//角色
	    var roleId = "";
	    //完成按钮的id
	    var userid=$('#submit').parent().attr('userid'); 
	    //发送类型
	    var Code_type="accountAdd_code";
	$(".fix>li>img[src$='s_check_no.png']").each(function(){
	    roleId += $(this).attr("_id")+",";
  });      	
	if($(".s_popup>.issue>h4").text()=="添加账号"){
		/*    <!-- 添加栏目----------	 --> */
   	//添加的完成
   	// var Code_type
   	var url = path+"/api/account/add";
    	var params = {"name" : name,"account" : account,"email" : email,"job" : job,"department" : department,"roleId" : roleId};		
    	$.ajax({    type: "POST",
             		 url: path+"/api/account/add",
             		 data: {"name":name,"account":account,"email":email,"job":job,"department":department,"departmentId":department,"roleId":roleId},
       			dataType: "json",
       			success: function(data){        				
       			//alert(data);	
       			//根据error code 判断之后看是否返回
       			if("1"==data.error_code){
       				//alert("添加成功");
       				$.ajax({type: "POST",
                    		 url: path+"/api/sms/verification_code/sendSe",
                    		 data: {"account" : account,"code_type" : Code_type},
              			 dataType: "json",
              			success: function(data1){
              			//$('#add_b_pho').text(data.account)
              			//发送成功的code为0
		         			if("0"==data1.error_code){
              			//显示提示添加成功并且发送短信成功
              			//如果发送成功，还要将登录码存入数据库
              			$('#add_b_pho').text(account);
     						$('.s_popup').hide();
   						$('.issue').hide();
    						$('.s_popup_box.k_cg_bg').show();
    						$('.s_popup_detailed.k_cg_content').show();        
       					}else{
       						wword.text(data1.error_msg);
       					}
							/* 显示错误 */
    	  					//error = data.message 
	   						}      		
       			}); 
       			}else{
       				wword.text(data.message);
       			}
       			}
       });
		/* ---------编辑栏目完成---------------------------------- */
   }else if($(".s_popup>.issue>h4").text()=="编辑账号"){
  	//编辑后的完成
   	//alert(roleId);
   	var url = path+"/api/account/edit";
    	var params = {"name" : name,"account" : account,"email" : email,"job" : job,"department" : department,"roleId" : roleId ,"userid":userid};		
    	$.ajax({type: "POST",
    		 url: path+"/api/account/edit",
     		 data: {"name" : name,"account" : account,"email" : email,"job" : job,"department" : department,"roleId" : roleId, "userid":userid},
			dataType: "json",
			success: function(data){
				if("1"==data.error_code){
					//alert('更改成功');
     				$('.s_popup').hide();
   				$('.issue').hide();
					window.location.href = path+"/ui/accountManagement";
   			}else{
					/* 显示错误 */
   				wword.text(data.message);
   			}          			   	  			
			}          		
  	})
   }
});   
});      
//页面加载
  var startIndex = 0;
  var pageSize = 10;
  var currentPage = 1;
  var pageCount = 0;
$(function(){
  sysuserList();
});
function sysuserList(){
  $.post(path+'/api/account/list', {
		"startIndex" : startIndex,
		"pagesize" : pageSize,				
		"keyWord" : $("#keyWord").val(),
		"status":$("#status").text(),
		"role":$("#role").text(),
		"department":$("#department").text(),				
		}, function(data) {
		sysuserhtml(data.sysuserList);	
		page(data.totalCount);
	    });
}
function sysuserhtml(data){
	//alert(data);
	var html = "";
	$.each(data,function(n,value) { 
		//alert(value.sjob);
		html += "<tr>"
		html += "<td>"+parseInt(n+1)+"</td>"
		html += "<td>"+value.sname+"</td>"
		html += "<td>"+value.saccount+"</td>"
		if(value.semail==null){
			html += "<td>"+""+"</td>"
		}else{
  		html += "<td>"+value.semail+"</td>"
		}
		if(value.sjob==null){
			html += "<td>"+""+"</td>"
		}else{
  		html += "<td>"+value.sjob+"</td>"
		}
		if(value.roles==null){
			html += "<td>"+""+"</td>"
		}else{
			html += "<td>"+value.roles+"</td>"
		}
		if(value.departmentName==null){
			html += "<td>"+""+"</td>"
		}else{
  		html += "<td>"+value.departmentName+"</td>"
		}
		if(value.astatus==0){
  		html += "<td id='status"+value.sid+"' class='k_zc'>正常</td>"
		}else{
  		html += "<td id='status"+value.sid+"' class='k_sx'>失效</td>"
		}
		html += "<td>"
		if(value.bak3=="super"){
  		html += ""
	}else{
  		html += "<shiro:hasPermission name='sys_account_update_button'><a href='javascript:;' id='update"+value.sid+"' class='k_bj' userId='"+value.sid+"'>编辑</a></shiro:hasPermission>"
      	if(value.astatus==0){
      		html += "<shiro:hasPermission name='sys_account_block_button'><a href='javascript:;' id='status"+value.sid+"' class='k_ty' userId='"+value.sid+"'  userAccount='"+value.saccount+"'>停用</a></shiro:hasPermission>"        		
      	}else{
      		html += "<shiro:hasPermission name='sys_account_block_button'><a href='javascript:;' id='status"+value.sid+"' class='k_qy' userId='"+value.sid+"' userAccount='"+value.saccount+"'>启用</a></shiro:hasPermission>"
      	}
  		if(value.astatus==0){
  			html += "<shiro:hasPermission name='sys_account_delete_button'><a href='javascript:;' id='del"+value.sid+"' class='k_sc' userId='"+value.sid+"'  userStatus='"+value.astatus+"' >删除</a></shiro:hasPermission>"        		
      	}else{
      		html += "<shiro:hasPermission name='sys_account_delete_button'><a href='javascript:;' id='del"+value.sid+"' class='k_sc' userId='"+value.sid+"'  userStatus='"+value.astatus+"' style='color:#03a9f4;'>删除</a></shiro:hasPermission>"
      	}
  	
	}
		html += "</td>"
		html += "</tr>"
	});
	$("#userList tbody").html(html)     	   	
}
/*<!-- //-----------------------------------页面加载完成------------------------------------- -->  */
$(function(){
	$(".m_xpages select").change(function(){
		pageSize = Number($(this).val());
		currentPage = 1;
		startIndex = 0;
		sysuserList();
	});
	
	$(".m_xpages a.prev").click(function(){
		if(currentPage > 1){
			currentPage--;
			startIndex -= pageSize;
			sysuserList();
		}
	});
	
	$(".m_xpages a.next").click(function(){
		if(currentPage < pageCount){
			currentPage++;
			startIndex += pageSize;
			sysuserList();
		}
	});
	
	$(".m_xpages :text").keyup(function(e){
		if(e.keyCode==13){
			var pageGo = $(this).val();
			if(/^[0-9]+$/.test(pageGo)){
				pageGo = Number(pageGo);
				if(pageGo<1 || pageGo>pageCount){
					alert('请输入合法页数');
				}else if(pageGo != currentPage){
					startIndex = (pageGo-1) * pageSize;
					sysuserList();
				}
			}else{
				alert('请输入合法页数');
			}
		}
	});
});
function page(totalCount){
	pageCount = totalCount/pageSize;
	if (totalCount % pageSize > 0)
		pageCount++;
	pageCount = parseInt(pageCount);
	
	currentPage =  startIndex / pageSize + 1;
	currentPage = parseInt(currentPage);
	
	if(currentPage == 1){
		$(".prev").addClass("pageDisable");
	}else{
		$(".prev").removeClass("pageDisable");
	}
	
	if(currentPage == pageCount || pageCount == 0){
		$(".next").addClass("pageDisable");
	}else{
		$(".next").removeClass("pageDisable");
	}
	
	$(".m_xpages>.mian>span:eq(1)").text('共'+totalCount+'条');
	$(".m_xpages>.mian>span:eq(2)").text(currentPage+'/'+pageCount+'页');
}
/* 页面显示功能结束 */
	//搜索的点击事件
$(function(){
  $('#searchA').click(function(){
   	var startIndex = 0;
   	var pageSize = 10;
   	var currentPage = 1;
   	var pageCount = 0;
   	$(function(){
   	  sysuserList();
   	});
  })
});

/* 	//点击启用按钮-------------------------------------------	 */
var w_word = $("#warning_word");
$(function(){
  $(document).on("click",".k_qy",function(){
		var id=$(this).attr('userId');
		var state=$(this).text();
		var userAccount = $(this).attr('userAccount');
		var delsy='#del'+id;
	 	$.post(path+'/api/account/operate', {
		"state" : state,
		"id":id,
		"userAccount":userAccount
		}, function(data) {
			//alert("2");
			if("1"==data.error_code){
	     	    //发送类型
	     	   var Code_type="operateQy_code";
             $.ajax({    type: "POST",
       		 url: path+"/api/sms/verification_code/sendQT",
       		 data: {"account":userAccount,"code_type" : Code_type},
 			 	 dataType: "json",
 			 	 success: function(data1){
 			 		 //$('#qy_b_pho').text(userAccount);	
 	    			 if("0"==data1.error_code){    				 
 	    				 //显示提示添加成功并且发送短信成功
 	    				 //如果发送成功，还要将登录码存入数据库
 	   				 	 //alert("启用短信发送成功");
 	   					 $('#qy_b_pho').text(userAccount);	
 	   					 $(delsy).css("color","#bdbdbd");
 	    			     $('.k_qy_bg').show();
 	    			     $('.k_qy_content').show();
 					}else{
 						/* 显示错误 */
 						//error = data.message      	  			
 						w_word.text(data1.error_msg );
 					}   			     
 			 	}
			}); 	
		}else{
			w_word.text(data.message );				
		}		
	   });
 });
});
//点击停用按钮---------------------------------	 -->
/* $(function(){
  $(document).on("click",".k_ty",function(){
  		var id=$(this).attr('userId');
  		var state=$(this).text();
  		var userAccount = $(this).attr('userAccount');
    	 	$.post(path+'/api/account/operate', {
			"state" : state,
			"id":id,
			"userAccount":userAccount
		}, function(data) {
			//alert("2");
			if("1"==data.error_code){
				  //alert("停用成功");
		     	    //发送类型
		     	   var Code_type="operateTy_code";
		           $.ajax({    type: "POST",
	         		 url: path+"/api/sms/verification_code/sendQT",
	         		 data: {"account":userAccount,"code_type" : Code_type},
	   			 	 dataType: "json",
	   			 	 success: function(data1){
	   			 		 //$('#ty_b_pho').text(userAccount);
	 	    			if("0"==data1.error_code){
	 	   				//显示提示停用成功并且发送短信成功
	 	   				//如果发送成功，提示
	 	   				  //alert("短信发送成功");
	 	  				  $('#ty_b_pho').text(userAccount);
	 			          $('.k_ty_bg').show();
	 			          $('.k_ty_content').show();
	 			          sysuserList();
	 					}else{
	 						//显示错误    	  			
	 						w_word.text(data1.error_msg ); 
	 					}	   			 		 	   			    
	   			 	 }
				}); 	
			}else{
				//显示错误
				w_word.text(data.message );
			}			
	   });
 });
}); */
/*点击删除按钮*/
$(document).on("click",".k_sc",function(){
	var userStatus = $(this).attr('userStatus');
	var id = $(this).attr('userId'); 
	//alert("del>>>"+userStatus+">id>>"+id);
	$('.s_confirm_del').attr("userStatus",userStatus);
	$('.s_confirm_del').attr("userId",id);
	if(userStatus==1){
  		$('.s_popup_delect,.issue_delect').show();
	}
	//del(userStatus,id);
});
/*点击删除的确定按钮*/
$(document).on("click",".s_confirm_del",function(){	
	var userStatus = $(this).attr('userStatus');
	var id = $(this).attr('userId');
	//alert("confirm>>>"+userStatus+">id>>"+id);
	$.post(path+'/api/account/delete', {
	 	"status":userStatus,
	 	"id":id	
	 }, function(data) {
		//alert("删除");
	 	console.log("进入删除方法");
		if("1"==data.error_code){
			console.log("删除成功");
			$('.s_popup_delect,.issue_delect').hide();
			sysuserList();
		}else{
			//显示错误
			w_word.text(data.message );
			$('.s_popup_delect,.issue_delect').hide();
		}			
	});		
});

/*点击停用按钮*/
$(document).on("click",".k_ty",function(){
	//alert(11111);  	
	var id=$(this).attr('userId');
	var state=$(this).text();
	var userAccount = $(this).attr('userAccount');
	
	//从cokie取出当前ID比对
	//var uid=$.cookie('uid');
	//if(id==uid){
	//	alert("不可对自己账号停用");
	//	return;
	//}
	//alert("del>>>"+userStatus+">id>>"+id);
	$('.s_confirm_ty').attr("state",state);
	$('.s_confirm_ty').attr("userId",id);
	$('.s_confirm_ty').attr("userAccount",userAccount);
	//del(userStatus,id);
	$('.s_popup_ty,.issue_ty').show();
});
/*点击停用的确定按钮*/
$(document).on("click",".s_confirm_ty",function(){
		var id=$(this).attr('userId');
		var state=$(this).attr('state');
		var userAccount = $(this).attr('userAccount');
		var delsy='#del'+id;
	 	$.post(path+'/api/account/operate', {
		"state" : state,
		"id":id,
		"userAccount":userAccount
	}, function(data) {
		//alert("2");
		if("1"==data.error_code){
			  //alert("停用成功");
	     	    //发送类型
	     	   var Code_type="operateTy_code";
	           $.ajax({    type: "POST",
         		 url: path+"/api/sms/verification_code/sendQT",
         		 data: {"account":userAccount,"code_type" : Code_type},
   			 	 dataType: "json",
   			 	 success: function(data1){
   			 		 //$('#ty_b_pho').text(userAccount);
 	    			if("0"==data1.error_code){
 	   				//显示提示停用成功并且发送短信成功
 	   				//如果发送成功，提示
 	   				  //alert("短信发送成功");
 	   				  $('.s_popup_ty,.issue_ty').hide();
 	   				  $(delsy).addClass('iblue');
 	  				  $('#ty_b_pho').text(userAccount);
 			          $('.k_ty_bg').show();
 			          $('.k_ty_content').show();
 			          sysuserList();
 					}else{
 						/* 显示错误 */
 						//error = data.message      	  			
 						/* 显示错误 */
 						//error = data.message      	  			
 						w_word.text(data1.error_msg ); 
 					}	   			 		 	   			    
   			 	 }
			}); 	
		}else{
			//显示错误
			w_word.text(data.message );
		}			
   });
});
/*点击三个弹出发送短信成功框的“完成”按钮*/
//点击完成按钮	
$(function(){
  $(document).on("click","#k_cg_wc,#k_ty_wc,#k_qy_wc",function(){
  	window.location.href = path+"/ui/accountManagement";
  });    
});
//-查询列表显示取出角色名字集合------------ -->
$(function(){
	$.post(path+'/api/account/getRoles', function(data) {	
	    $.each($.parseJSON(data.obj),function(i,d){
		    var str = "";
		    str += '<li>';
		    str += d.name;
		    str += '</li>';
		    $("#role_name").append(str);
	    })
  }); 
});
//-查询列表显示取出部门名字集合------------ -->
$(function(){
	$.post(path+'/api/account/getDepartments', function(data) {
	    $.each($.parseJSON(data.obj),function(i,d){
		    var str = "";
		    str += '<li>'+d.name+'</li>';
		    $("#department_name").append(str);
		    console.log(111);
	    })
  }); 
});




$(function(){
	$.post(path+'/api/account/getDepartments', function(data) {	
	    $.each($.parseJSON(data.obj),function(i,d){
		    var str = "";
		    str += '<li _depart_Id="'+d.id+'">'+d.name+'</li>';
		    $("#department_select_name").append(str);
	    })
  }); 
});

$('.s_cancel_del,.issue_delect span').click(function(){
  $('.s_popup_delect,.issue_delect').hide();
});	
$('.s_cancel_ty,.issue_ty span').click(function(){
	$('.s_popup_ty,.issue_ty').hide();
	});
</script>
<script type="text/javascript">
var auths = "<%=session.getAttribute("authoritys")%>";
</script>
</body>
</html>